import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import dongbai.soft.ShedApplication;
import dongbai.soft.entity.TypeEntity;
import dongbai.soft.service.TypeService;
import dongbai.soft.utils.PageUtils;
import org.apache.commons.lang.StringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.*;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = ShedApplication.class)
public class test {
    @Autowired
    private TypeService typeService;

    @Test
    public void test1() {
        Map<String, Object> params = new HashMap<>();
        params.put("name", "数码");
        params.put("size", -1);
        params.put("page", 1);
        params.put("parentID", "");
        PageUtils page = typeService.queryPage(params);
        if (!StringUtils.isEmpty((String) params.get("name"))) {
            List<TypeEntity> typeEntities = (List<TypeEntity>) page.getList();
            Set<TypeEntity> children = new HashSet<>();
            for (TypeEntity typeEntity : typeEntities) {
                if (typeEntity.getParentid().equals("0")) {
                    children.addAll(typeService.list(new QueryWrapper<TypeEntity>()
                            .eq("parentID", typeEntity.getTid())));
                }
            }
            children.addAll(typeEntities);
            page.setList(new ArrayList<>(children));
        }
        System.out.println(page);

    }
}
